import java.util.Calendar;
import java.util.HashSet;
import java.util.Iterator;


public class UserActivity {
	Calendar date = null;
	int answered = 0;
	int questioned = 0;
	int commented = 0;
	int revision = 0;
	int asked = 0;
	/* ArrayList<String> badges = null; */
	HashSet<String> badges = null;

	UserActivity() {

	}

	UserActivity(Calendar date) {
		this.date = date;
	}

	public void add(UserActivity u) {
		this.answered += u.answered;
		this.questioned += u.questioned;
		this.commented += u.commented;
		this.revision += u.revision;
		this.asked += u.asked;

		if (u.badges != null) {
			if (this.badges == null) {
				badges = new HashSet<String>();
			}
			this.badges.addAll(u.badges);
		}
	}

	public String toCSVLine() {
		String time = Integer.toString(date.get(Calendar.DATE)) + "-"
				+ Integer.toString(date.get(Calendar.MONTH) + 1) + "-"
				+ Integer.toString(date.get(Calendar.YEAR));
		String activities = answered + "," + commented + ","
				+ revision + "," + asked;
		return time + "," + activities;
	}

	@Override
	public String toString() {
		if (date == null) {
			String warning = "User Activities with Null Pointer";
			return warning;
		}
		String info = String
				.format("%d-%d-%d - ans: %d, qns: %d, comments: %d, rev: %d, asked: %d",
						date.get(Calendar.DATE), date.get(Calendar.MONTH) + 1,
						date.get(Calendar.YEAR), answered, questioned,
						commented, revision, asked);

		StringBuffer sb = new StringBuffer();

		/*
		 * if (badges != null){ int len = badges.toArray().length; for (int i =
		 * 0; i < len; i++) { sb.append(badges.get(i)); if (i < len - 1)
		 * sb.append(", "); } }
		 */

		if (badges == null || badges.isEmpty()) {
			return info;
		} else {
			Iterator<String> it = badges.iterator();
			while (it.hasNext()) {
				sb.append((String) it.next() + ", ");
			}
			/*
			 * for (String badge: badges){ sb.append(badge + ", "); }
			 */
			String infoString = info + ", Badges: " + sb;
			infoString.substring(0, infoString.length() - 2);
			return infoString.substring(0, infoString.length() - 2);
		}
	}
}
